﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.ServiceModel;
using Server.communication;
using System.ServiceModel.Description;

namespace Server
{
    public partial class Form1 : Form
    {
        private static int PORT = 8000;
        private static string IP = Dns.GetHostName();
        private static string urlService;
        private ServiceHost host = null;

        public Form1()
        {
            InitializeComponent();
            InitServer();
        }

        private void InitServer()
        {
            try
            {
                urlService = "net.tcp://" + IP + ":" + PORT + "/katom";
                host = new ServiceHost(typeof(Communicator));
                NetTcpBinding tcpbinding = new NetTcpBinding();
                tcpbinding.TransactionFlow = false;
                tcpbinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
                tcpbinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                tcpbinding.Security.Mode = SecurityMode.None;
                host.AddServiceEndpoint(typeof(Icommunicator), tcpbinding, urlService);

                ServiceMetadataBehavior metadata = new ServiceMetadataBehavior();
                metadata.HttpGetEnabled = true;
                metadata.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                metadata.HttpGetUrl = new Uri("http://" + IP + ":" + (PORT + 1) + "/katom");
                host.Description.Behaviors.Add(metadata);
                host.Open();
            }
            catch (Exception e)
            {
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

       
        

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            host.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            
        }
    }
}
